package GUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.SwingConstants;

import DataObjects.TotalHoursInMonthAccess;
import Messages.MessageAddOrUpdateWorkingHoursFromDoh;

/**
 * Class for creation pop window that show total of work hours of employee.This window pop when employee 
 * press button exitButton in class PfClock_In_Out_Second
 * @author Andrey,Igor,eugen
 *
 */

public class AccessClockInClockOut extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = -5258907092541936230L;

	private MainMenu mainMenu;
	
	private JPanel panelUpon ;
	private JPanel panelDown;
	private JPanel panelMiddle;
	
	private  JLabel todayLbl;
	private  JLabel monthLbl;
	private  JLabel warningTxt;
	
	private  JTextField monthTxt;
	private  JTextField todayTxt;
	
	private Vector<String> workHours;
	private Vector<String> workMonthHours;
	
	private int hours_in;
	private int minuts_in;
	private int hours_out;
	private int minuts_out;
	private float tempSec;
	private int Seconds;
	private float tempMinuts;
	private int tempMinuts2;
	private int tempHours;
	private String hoursMonth;
	private String minutesMonth;
	private String secondsMonth;
	public int flagHrs;

	private float totalTodayTime;
	private float totalMonthTime;
	
	public AccessClockInClockOut (MainMenu mm,Vector<String> res,Vector<String> vector, int flagHrs1)
	{
	
		super();
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
		this.setSize(400, 300);
		this.mainMenu=mm;
		this.workHours=res;
		 
		this.workMonthHours=vector; 		 
		this.setVisible(true);
		this.flagHrs=flagHrs1;
		initialize ();
		
	}
	
public void	initialize ()
	{
	 
	  Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
	  this.setLocation((sSize.width-this.getWidth())/2,(sSize.height-this.getHeight())/2);
	  this.getContentPane().add(getDownPanel());
	  this.getContentPane().add(getMiddlePanel());
	  this.getContentPane().add(getUponPanel(this));
	 
	 }
		
	/**
	 * Method for creation JPanel panelUpon that includes JButton okBtn(okBtn button that return
	 * user to first screen PfClock_In_Out_First)
	 * @param acico
	 * @return JPanel panelUpon
	 */
     public JPanel getUponPanel(AccessClockInClockOut acico)
     {
    	 final AccessClockInClockOut acic;
    	 acic=acico;
    	 panelUpon=new JPanel(); 
    	 panelUpon.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    	 JButton okBtn = new JButton("OK");
    	 okBtn.addActionListener(new java.awt.event.ActionListener() {
 			public void actionPerformed(java.awt.event.ActionEvent e) {
 				
 				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
 				mainMenu.getContentPane().add(new PfClock_In_Out_First(mainMenu), BorderLayout.CENTER);
 				mainMenu.getContentPane().validate();	
 				acic.dispose();
			}
		});
    	 okBtn.setPreferredSize(new Dimension(100,50));
    	 panelUpon.add(okBtn);
    	 
    	 return panelUpon;
     }

    
    /**
     * Method for creation JPanel panelDown and calculation total quantity of work hours today and show it
     * @return JPanel panelDown
     */
	public JPanel getDownPanel()
     {
		 		
    	 panelDown=new JPanel(); 
    	 panelDown.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    	 
    	 todayTxt = new JTextField();
    	 todayTxt.setFont(new Font("Tahoma", Font.PLAIN, 16));
   //-------------------------------------------------------------calculate the quantity of work hours today------------------------------------------- 	
    	 
   	 TotalHoursInMonthAccess totHrs = new TotalHoursInMonthAccess(workHours);
   	
   	 
   	 try {
		totHrs.CalculateMonthHours();
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
 
	     todayTxt.setText(totHrs.getHoursOfMonth()+":"+totHrs.getMinutesOfMonth()+":"+totHrs.getSecondsOfMonth()); 
    	 todayTxt.setEditable(false);
    	 todayTxt.setPreferredSize(new Dimension(120,40));
    	 panelDown.add(todayTxt); 
    	 
    	 todayLbl = new JLabel("   שעות היום   :");
    	 todayLbl.setFont(new Font("Tahoma", Font.BOLD, 18));
    	 todayLbl.setLabelFor(todayTxt);
    	 panelDown.add(todayLbl);
    	 
    	 
            tempHours = Integer.parseInt(totHrs.getHoursOfMonth());       // get hours of current day
           
         if(tempHours>12||this.flagHrs==1)                                // check if totHrs.getHoursOfMonth() >12   convert to int 
    	  {
    		 warningTxt = new JLabel(" נא לבדוק זמן הכניסה והיציאה, יש חריגה ");
    		 warningTxt.setVerticalAlignment(SwingConstants.BOTTOM);
    		 warningTxt.setForeground(Color.RED);
    		 warningTxt.setFont(new Font("Tahoma", Font.BOLD, 18));
    		// warningTxt.setForeground(fg)
        	// monthLbl.setLabelFor(monthLbl);
    		 panelDown.add(warningTxt);
    	     warningTxt.setVisible(true);
    	   
     	   }
     
    	 
    	 return panelDown;
     }
	
	
	public int getTempHours() {
		return tempHours;
	}

	public void setTempHours(int tempHours) {
		this.tempHours = tempHours;
	}
	
     
	/**
     * Method for creation JPanel panelMiddle and calculation total quantity of work hours of the month  and show it
     * @return JPanel panelMiddle
     */
     public JPanel getMiddlePanel()
     {
    	 panelMiddle=new JPanel();
    	 panelMiddle.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    	 
    	 monthTxt = new JTextField();
    	 monthTxt.setFont(new Font("Tahoma", Font.PLAIN, 16));
    	 
    	   
    	 TotalHoursInMonthAccess totHrs1 = new TotalHoursInMonthAccess(workMonthHours);	
    	
    	 try {
			totHrs1.CalculateMonthHours();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    
    
    	 monthTxt.setText(totHrs1.getHoursOfMonth()+":"+totHrs1.getMinutesOfMonth()+":"+totHrs1.getSecondsOfMonth()); 
    	 
    	 monthTxt.setEditable(false);
    	 monthTxt.setPreferredSize(new Dimension(120,40));
    	 panelMiddle.add(monthTxt);
    	 
    	 monthLbl = new JLabel("שעות החודש   :");
    	 monthLbl.setFont(new Font("Tahoma", Font.BOLD, 18));
    	 monthLbl.setLabelFor(monthLbl);
    	 panelMiddle.add(monthLbl);
    	 
    	
    	 
    	 return panelMiddle;
     }
     

	}

